﻿using Gonte.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections;
using System.Xml.Serialization;
using System;
using System.Collections.Generic;

namespace MyUtilitiesTest
{
    /// <summary>
    ///This is a test class for ObjectFactoryTest and is intended
    ///to contain all ObjectFactoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ObjectFactoryTest
    {

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for creating an instance of a field of a nested generic object
        ///</summary>
        [TestMethod()]
        public void GetItemTypeForListOfListOfStringsTest()
        {
            ICollection collection = new List<List<String>>();
            XmlElementAttribute attribute = null;

            Assert.AreEqual(typeof(List<String>), ObjectFactory.GetItemType(collection, attribute));
        }

        /// <summary>
        ///A test for creating an instance of a field using a constructor if the field os not generic
        ///</summary>
        [TestMethod()]
        public void CreateObjectUsingConstructor()
        {
            SimpleParentObject parent = new SimpleParentObject();
            parent.Name = "TheParent";

            SimpleChildObject child = (SimpleChildObject)ObjectFactory.CreateObject(
                                        typeof(SimpleChildObject),
                                        new Type[] { typeof(SimpleParentObject) },
                                        new Object[] { parent }
                                        );

            Assert.IsNotNull(child.Parent);
            Assert.AreEqual(parent.Name, child.Parent.Name);
        }
    }
}
